import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  list = '/genTable/pageGenTable',
  deleteGenTable = '/genTable/deleteGenTable',
  importDbTable ='/genTable/importDbTable',
  importDocumentTable ='/genTable/importDocumentTable',
  genCode ='/gen/code',
  getGenTable ='/genTable/getGenTable',
  getGenInfo ='/genTable/getGenInfo',
  listGenTableColumn ='/genTable/listGenTableColumn',
  listGenTableIndex ='/genTable/listGenTableIndex',
  saveOrUpdateGenTableInfo ='/genTable/saveOrUpdateGenTableInfo',
  batchDeleteGenTableIndex ='/genTable/batchDeleteGenTableIndex',
  batchDeleteGenTableColumn ='/genTable/batchDeleteGenTableColumn',
  batchDeleteGenTable ='/genTable/batchDeleteGenTable',
}

/**
 * 列表接口
 * @param params
 */
 export const list = (params) => defHttp.get({url: Api.list, params});

 export const importDbTable = (params) => defHttp.post({url: `${Api.importDbTable}`, params});
 export const importDocumentTable = (params) => defHttp.post({url: `${Api.importDocumentTable}`, params});
 /**
  * 生成代码
  */
 export const genCode = (params) => defHttp.post({url: `${Api.genCode}`, params});

 /**
  * 获取相关信息
  * @param params 表id
  * @returns 
  */
 export const getGenTable = (params) => defHttp.get({url: `${Api.getGenTable}?tableId=${params}`});
 export const getGenInfo = (params) => defHttp.get({url: `${Api.getGenInfo}?tableId=${params}`});
 export const listGenTableColumn = (params) => defHttp.get({url: `${Api.listGenTableColumn}?tableId=${params}`});
 export const listGenTableIndex = (params) => defHttp.get({url: `${Api.listGenTableIndex}?tableId=${params}`});

 export const saveOrUpdateGenTableInfo = (params) => defHttp.post({url: `${Api.saveOrUpdateGenTableInfo}/`, data: params});
 export const batchDeleteGenTableIndex = (params) => defHttp.delete({url: `${Api.batchDeleteGenTableIndex}?ids=${params}` });
 export const batchDeleteGenTableColumn = (params) => defHttp.delete({url: `${Api.batchDeleteGenTableColumn}?ids=${params}` });

 /**
 * 批量删除gen_table
 * @param params
 */
export const batchDeleteGenTable = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.batchDeleteGenTable, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};


 export const deleteGenTable = (params) => defHttp.delete({url: `${Api.deleteGenTable}?id=${params.id}`});